package cn.chengpengper.seckill.reservation.application.command;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * @author chengpeng.hu
 */
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SeckillReservationConfigCommand implements Serializable {
    private static final long serialVersionUID = 4194566141358134767L;
    /**
     * 商品id
     */
    private Long goodsId;

    /**
     * 预约人数上限
     */
    private Integer reserveMaxUserCount;

    /**
     * 预约开始时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date reserveStartTime;

    /**
     * 预约结束时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date reserveEndTime;

    public boolean isEmpty() {
        return this.goodsId == null
                || this.reserveMaxUserCount == null
                || this.reserveMaxUserCount <= 0
                || this.reserveStartTime == null
                || this.reserveEndTime == null
                || this.reserveStartTime.after(this.reserveEndTime);
    }

}
